import MySql.Goods;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class ShowGoods1Servlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out=response.getWriter();
        String s=request.getParameter("item");
        String ss="item-"+s+"-";
        Cookie[] cookies=request.getCookies();
        Cookie cookie1=null;
        Cookie cookie2=null;
        Cookie cookie3=null;
        Cookie cookie4=null;
        Cookie cookie5=null;

        out.println("item-"+s+"-title");

        for (Cookie cookie:cookies){
            if(cookie.getName().equals("item-"+s+"-title")) {
                cookie1 = new Cookie("now-title", cookie.getValue());
            }else if(cookie.getName().equals("item-"+s+"-brief")){
                cookie2=new Cookie("now-brief",cookie.getValue());
            }else if(cookie.getName().equals("item-"+s+"-kind")){
                cookie3=new Cookie("now-kind",cookie.getValue());
            } else if(cookie.getName().equals("item-"+s+"-price")){
                cookie4=new Cookie("now-price",cookie.getValue());
            } else if(cookie.getName().equals("item-"+s+"-id")){
                cookie5=new Cookie("now-id",cookie.getValue());
            }
        }
        cookie1.setMaxAge(60*60*60);
        cookie2.setMaxAge(60*60*60);
        cookie3.setMaxAge(60*60*60);
        cookie4.setMaxAge(60*60*60);
        cookie5.setMaxAge(60*60*60);
        cookie1.setPath(request.getContextPath()+"/");
        cookie2.setPath(request.getContextPath()+"/");
        cookie3.setPath(request.getContextPath()+"/");
        cookie4.setPath(request.getContextPath()+"/");
        cookie5.setPath(request.getContextPath()+"/");
        response.addCookie(cookie1);
        response.addCookie(cookie2);
        response.addCookie(cookie3);
        response.addCookie(cookie4);
        response.addCookie(cookie5);
        response.sendRedirect("show-good.jsp");
    }
}
